{% extends "main/base.html" %}
{% load static i18n %}
{% block title %}{% trans '用户管理' %}{% endblock %}
{% block content %}
<div class="row">{% if perms.main.add_employee %}
    <div class="col-lg-12">
        <section class="panel">
            <header class="panel-heading">
                {% trans '添加用户' %}
                {% if form.errors %}<p>{% trans "提交的数据有误,请认真检查!" %}</p>{% endif %}
                {% if user_created %}<p>{% trans "用户创建成功,请妥善保存帐号和密码!" %}</p>{% endif %}
                {% if user_exist %}<p>{% trans "用户名" %}{{ user_exist.username }}{% trans "已经存在!" %}</p>{% endif %}
            </header>
            <div class="panel-body">
                <div class="col-lg-9">
                <form class="form-inline" method="post" action="{{ request.path }}?next={{ request.GET.next }}">{% csrf_token %}
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon">{% trans '用户名' %}:</span>
                            <input type="text" name="username" required id="id_username" class="form-control">{{ form.username.errors }}
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon">{% trans '密码' %}:</span>
                            <input type="password" name="password" required id="id_password" class="form-control">{{ form.password.errors }}
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <button type="submit" class="btn btn-danger">{% trans "添加" %}</button>
                        </div>
                    </div>
                </form>
                </div>
                <div class="col-lg-3" align="right">
                    <a href="{% url 'main:group_list' %}?next={{ request.path }}"><label class="btn btn-primary">{% trans '权限分组' %}</label></a>
                </div>
            </div>
      </section>
    </div>{% endif %}
    <div class="col-lg-12">
        <section class="panel table-responsive">
            <div class="panel-body">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>{% trans 'No.' %}</th>
                            <th>{% trans 'ID' %}</th>
                            <th>{% trans '用户名' %}</th>
                            <th>{% trans '姓氏' %}</th>
                            <th>{% trans '名字' %}</th>
                            <th>{% trans '邮箱' %}</th>
                            <th>{% trans '注册于' %}</th>
                            <th>{% trans '最后登录' %}</th>
                            <th>{% trans '有效' %}</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>{% for d in users_have %}
                        <tr class="{% cycle '' 'active' %}">
                            <td>{{ forloop.counter }}</td>
                            <td>{{ d.pk }}</td>
                            <td><a href="">{{ d.username }}</a></td>
                            <td>{{ d.last_name|default_if_none:"" }}</td>
                            <td>{{ d.first_name|default_if_none:"" }}</td>
                            <td>{{ d.email|default_if_none:"" }}</td>
                            <td>{{ d.date_joined }}</td>
                            <td>{{ d.last_login }}</td>{% if d.is_active %}
                            <td><span class="label label-primary">{% trans '是' %}</span></td>{% else %}<td><span class="label label-danger">{% trans '否' %}</span></td>{% endif %}
                            {% if perms.main.change_employee %}
                            <td align="right"><a href="{% url 'main:user_update' d.pk %}?next={% url 'main:user_list' %}"><button class="btn btn-success btn-xs"><i class="fa fa-pencil"></i></button></a></td>{% endif %}
                        </tr>{% endfor %}
                    </tbody>
                </table>
            </div>
        </section>
    </div>
</div>
{% endblock %}